/*
 *  /^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}([\w]+)(.[\w]+){1,2}$/;
 * http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
*/

//    The page gives doctor the functionality to bid .      
//    The data will be inserted/updated to the tbl_bidding.                                
//    Author: Rupinder Saini                                                                    
//    Date: May 15,2006 

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SiteManager;
using System.Data.SqlClient;

//public partial class Doctor_bidding : System.Web.UI.Page
public partial class modifypremiumdetails : System.Web.UI.Page
{
    // creating an instance of manager class
    Manager mgr = new Manager(true,"ConnectionString");
    protected void Page_Load(object sender, EventArgs e)
    {        
      // check if doctor logged in
      localFunction drchk= new localFunction();
        drchk.checkDoctorLogin(true);
        if (!Page.IsPostBack)
        {
            string SQL = @"select prof_desc,photo,Website from tbl_drpremium 
                        inner join tbl_bidding on tbl_bidding.dr_id=tbl_drpremium.dr_id
	                    where tbl_drpremium.dr_id="+Session["userid"]+" and trx_status=1";
            using (SqlDataReader dr=(new Manager()).ExecuteQuery(SQL))
            {
                if (dr.Read())
                {
                    txt_profdesc.Text = dr.GetString(0);
                    txt_web.Text = dr.GetString(2);
                    string str_path = dr.GetString(1);                    
                   

                    photo.Text  = getImage(str_path);
                    dr.Close();
                }
                else
                {
                    dr.Close();
                    Response.Write(@"<Script>alert('You are not registred for these features')
                        window.location.href='doctorcontent.aspx'
                        </script>");

                }
            }
        }
    }

   

    protected void btn_bid_Click(object sender, ImageClickEventArgs e)
    {
        string strdesc = txt_profdesc.Text.Replace("'","''");
        string strweb = txt_web.Text.Replace("'", "''");
        string strphoto = hidphoto.Value;
        string errMsg = string.Empty;
        if (fupl_photo.HasFile)
        {
            errMsg = mgr.UpLoadFile(fupl_photo, Request.PhysicalApplicationPath + "/images/Dr_images/", ".jpg|.bmp|.gif", 512000);
            if (errMsg.Length > 0)
            {
                lbl_fail.Text = errMsg;
                lbl_fail.Visible = true;
                return;
            }
            else
            {
                if (System.IO.File.Exists(Request.PhysicalApplicationPath + "/images/Dr_images/" + strphoto))
                    System.IO.File.Delete(Request.PhysicalApplicationPath + "/images/Dr_images/" + strphoto);
                strphoto = fupl_photo.FileName;
                hidphoto.Value = strphoto;
                photo.Text = getImage(strphoto);
            }
        }
        
        string strSql="update tbl_drpremium set prof_desc='"+strdesc+"',photo='"+strphoto+"',Website='"+strweb+"' where dr_id="+Session["userid"]; 
        mgr.ExecuteUpdate(strSql);
        lbl_fail.Visible = true;
        lbl_fail.Text = "Details updated succesfully";

    }

    private string getImage(string str_path)
    {
        if (System.IO.File.Exists(Request.PhysicalApplicationPath + "/images/Dr_images/" + str_path))
        {
            if (str_path.Trim().Length > 0)
            {
                str_path = mgr.getThumbnaleImage("../images/Dr_images/" + str_path, 130, 100, false, "");
            }
            else
            {
                str_path = mgr.getThumbnaleImage("../images/Dr_images/silhouette-male.gif", 80, 100, false, "");
            }
        }
        else
        {
            str_path = mgr.getThumbnaleImage("../images/Dr_images/silhouette-male.gif", 80, 100, false, "");
        }
        return str_path;
    }

    
}
